<script setup>
import {onMounted, ref, shallowReactive, shallowRef} from "vue";
import router from "../../../router";
import {saveApi} from "../../../api/schedule.js";
import {RULE} from "../../../const";
import MyNav from "../../../components/MyNav.vue";
import MyForm from "../../../components/MyForm.vue";
import {getResponseData} from "../../../util";

/* ==================== 添加表单 ==================== */


// 表单项
let items = shallowRef([
  {'label': '课程名称', 'prop': 'courseName', 'required': true, 'span': 12},
  {'label': '学时数', 'prop': 'hours', 'required': true, 'span': 12},
  {'label': '开始时间', 'prop': 'startTime', type: 'datetime', 'required': true, 'span': 12},
  {'label': '结束时间', 'prop': 'endTime', type: 'datetime', 'required': true, 'span': 12},
  {'label': '课程ID', 'prop': 'courseId', 'hidden': false, 'required': true, 'span': 12},
  {'label': '排课描述', 'prop': 'info', 'type': 'textarea'},
]);

// 获取当前课程记录
let course = JSON.parse(sessionStorage.getItem('course'));
// 表单值
let data = shallowReactive({});
data.courseName = course.name
data.courseId = course.id
// 表单规则
let rules = {
  /*'name': RULE.REALNAME,
  'phone': RULE.PHONE,
  'emergencyContactPhone': RULE.PHONE,
  'idCard': RULE.IDCARD,
  'info': RULE.COMMON_INFO,*/
};

/* ==================== 加载函数 ==================== */
onMounted(() => {
});

</script>

<template>

  <my-nav :items="[
    {'icon': 'Avatar', 'label': '排课管理', 'url': '/'},
    {'icon': 'User', 'label': '排课列表', 'url': '/Schedule'},
    {'icon': 'Plus', 'label': '添加排课'},
  ]"/>

  <el-divider/>

  <el-card class="student-insert-card" header="添加排课信息">
    <my-form type="insert"
             :items="items"
             :data="data"
             :rules="rules"
             :api="saveApi"
             :fn="() => router.push('/Schedule')"/>
  </el-card>
</template>

<style scoped lang="scss">
.student-insert-card {
  width: 60%;
  margin: auto;
}
</style>